package com.flame.session.controller;

import com.flame.auth.core.annotation.HasAuth;
import com.flame.core.protocol.Result;
import com.flame.session.controller.vo.ForceLogoutVo;
import com.flame.session.controller.vo.OnlineUserVo;
import com.flame.session.service.OnlineUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OnlineUserController {

    @Autowired
    private OnlineUserService onlineUserService;

    @HasAuth("online-user")
    @PostMapping("/online-user/list")
    public Result list(@RequestBody OnlineUserVo onlineUserVo) {
        return Result.success(onlineUserService.list(onlineUserVo));
    }

    @HasAuth("online-user:force-logout")
    @Transactional
    @PostMapping("/online-user/force-logout")
    public Result forceLogout(@RequestBody ForceLogoutVo forceLogoutVo) {
        onlineUserService.forceLogout(forceLogoutVo.getPrimaryId());
        return Result.success();
    }
}
